package net.openvision.music.ui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;

import net.openvision.music.model.Bar;

public class JBar extends JComponent {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5128856966809557594L;

	private static final String uiClassID = "BarUI";
	
	public static final int DEFAULT_HEIGHT = 30;
	public static final int MINIMAL_WIDTH = 100;
	
	protected Rectangle2D barSize;
	protected Bar model;
	
	public JBar(Bar model) {
		this.model = model;
		setMinimumSize(new Dimension(MINIMAL_WIDTH, DEFAULT_HEIGHT));
	}
	
//	public void setUI(BarUI ui) {
//		super.setUI(ui);
//	}
//
//	public void updateUI() {
//		if (UIManager.get(getUIClassID()) != null) {
//			setUI((BarUI) UIManager.getUI(this));
//		} else {
//			setUI(new BasicBarUI());
//		}
//	}
//
//	public BarUI getUI() {
//		return (BarUI) ui;
//	}
//
//	public String getUIClassID() {
//		return uiClassID;
//	}
	
	@Override
	public Dimension getPreferredSize() {
		return new Dimension(MINIMAL_WIDTH, DEFAULT_HEIGHT);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D gfx = (Graphics2D)g;
		Dimension bsize = getBarSize();
		gfx.drawRect(0, 0, (int)bsize.getWidth(), (int)bsize.getHeight()-1);
		double ld = bsize.getHeight() / 4;
		for (int i = 1; i < 4; i++) {
			gfx.draw(new Line2D.Double(0d, ld*i, bsize.getWidth(), ld*i));
		}
	}
	
	public Dimension getBarSize() {
		return new Dimension((int)getPreferredSize().getWidth(), DEFAULT_HEIGHT);
	}
}
